package kr.co.doriclassic.chpater22test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class Student2 implements Comparable<Student>{
	int number;
	String name;
	public Student2(int number, String name) {
		this.number = number;
		this.name = name;
	}
	@Override
	public String toString() {
		return String.format("학번 : %s, 이름 : %s", number, name);
	}
	@Override
	public int compareTo(Student o) {
		// TODO Auto-generated method stub
		return o.name.hashCode()-name.hashCode();
	}
	
}

public class SortTest {
	public static void main(String[] args) {
		ArrayList<Student2> st = new ArrayList<>();
		st.add(new Student2(1001, "김씨"));
		st.add(new Student2(1002, "이씨"));
		st.add(new Student2(1003, "박씨"));
		
		Comparator<Student2> cmp = new Comparator<Student2>() {
			
			@Override
			public int compare(Student2 o1, Student2 o2) {
				// TODO Auto-generated method stub
				return o2.name.hashCode()-o1.name.hashCode();
			}
		};
		Collections.sort(st, cmp);
		System.out.println(st);
	}

	
}
